<template>
  <div class="app-container">
    <el-card>
      <el-form
        :model="queryParams"
        ref="queryRef"
        :inline="true"
        v-show="showSearch"
      >
        <el-form-item label="客户姓名">
          <el-input
            v-model="queryParams.name"
            placeholder="请输入客户姓名"
            clearable
            @keyup.enter="handleQuery"
          />
        </el-form-item>

        <el-form-item label="通话状态">
          <el-select
            v-model="queryParams.callStatus"
            clearable
            placeholder="请选择状态"
            style="width: 240px"
          >
            <el-option
              v-for="dict in call_status"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
            ></el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="Search"
@click="handleQuery"
            >搜索</el-button
          >
          <el-button icon="Refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>

      <el-row :gutter="10" class="mb8">
        <right-toolbar
          v-model:showSearch="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>

      <el-table
        v-loading="loading"
        :data="postList"
        stripe
        border
        max-height="500"
      >
        <el-table-column label="客户姓名" align="center" prop="applyName" />
        <el-table-column label="呼叫时间" align="center" prop="callTime" />
        <el-table-column label="呼叫类型" align="center">
          <template #default="scope">
            <span>{{ scope.row.callType == 0 ? "呼入" : "呼出" }}</span>
          </template>
        </el-table-column>
        <el-table-column label="通话状态" align="center">
          <template #default="scope">
            <span :class="scope.row.callStatus == '0' ? 'red' : ''">
              {{
                call_status.find((item) => item.value == scope.row.callStatus)
                  ? call_status.find(
                      (item) => item.value == scope.row.callStatus,
                    ).label
                  : ""
              }}
            </span>
          </template>
        </el-table-column>
        <el-table-column label="客服姓名" align="center" prop="agentName" />
        <el-table-column
          label="接听时间"
          align="center"
          prop="answerCallTime"
        />
        <el-table-column label="结束时间" align="center" prop="endCallTime" />
        <el-table-column label="通话时长" align="center" prop="duration" />
        <el-table-column
          label="设备编号"
          align="center"
          prop="imei"
          width="250"
        />

        <el-table-column
          label="操作"
          align="center"
          class-name="small-padding fixed-width"
        >
          <template #default="scope">
            <el-button
              link
              v-if="scope.row.callStatus == '0'&&isAgentPeople==true"
              type="primary"
              @click="edit(scope.row)"
              >回拨</el-button
            >
          </template>
        </el-table-column>
      </el-table>

      <pagination
        v-show="total > 0"
        :total="total"
        v-model:page="queryParams.page"
        v-model:limit="queryParams.limit"
        @pagination="getList"
      />
    </el-card>
    <div>
      <dialogComponent
        v-if="screen"
        :homeApplyId="homeApplyId"
        :homeApplyName="homeApplyName"
        :imei="imei"
        @closed="closed"
      ></dialogComponent>
    </div>
    <!-- 添加或修改岗位对话框 -->
  </div>
</template>

<script setup name="CustomerServiceAgents">
const { proxy } = getCurrentInstance();
const { sys_normal_disable, sys_user_sex, call_status, call_type } =
  proxy.useDict(
    'sys_normal_disable',
    'sys_user_sex',
    'call_status',
    'call_type',
  )
const router = useRouter();
import dialogComponent from './../deviceDinding/dialog.vue';
import { callRecord, isAgent } from "@/api/smartSpeaker/index"
const showSearch = ref(true);
const loading = ref(true);
const postList = ref([]);
const open = ref(false);
const total = ref(0);
const isAgentPeople=ref(false);
const screen = ref(false);
const homeApplyId = ref('');
const homeApplyName = ref('');
const imei = ref('');

const data = reactive({
  form: {},
  queryParams: {
    page: 1,
    limit: 10,
    name: undefined,
    callStatus: undefined,
  },
});

const { queryParams, form } = toRefs(data)

function edit(data) {
  homeApplyId.value = data.homeBedApplyId
  homeApplyName.value = data.applyName
  imei.value = data.imei
  screen.value = true;
}

/** 查询岗位列表 */
function getList() {
  loading.value = true;
  callRecord(queryParams.value).then((response) => {
    postList.value = response.page.list;
    total.value = response.page.totalCount;
    loading.value = false;
  })
}
function handleQuery() {
  getList();
}
function resetQuery() {
  queryParams.value = {
    page: 1,
    limit: 10,
    name: undefined,
    callStatus: undefined,
  };
  getList();
}
function closed(data) {
  screen.value = data;

}
function isAgentBoole(){
  isAgent().then(res=>{
    isAgentPeople.value=res.isAgent
  })
}
isAgentBoole()
getList();
</script>
<style scoped>
.red {
  color: red;
}
:deep(.el-dialog.is-fullscreen) {
  width: 90%;
  margin-right: 8px;
}
</style>
